package com.tedu.egweibo.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@MapperScan("com.tedu.egweibo.mapper")
@EnableSwagger2WebMvc
public class Config {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                //配置文档信息
                .apiInfo(apiInfo())
                //用于定义为我们项目的哪个包下的类生成文档(通常仅指定controller包)
                .select().apis(RequestHandlerSelectors.basePackage("com.tedu.egweibo.controller"))
                //指定为哪些url生成文档,这里为所有
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //当前项目名(生成文档网页的标题)
                .title("新微博项目")
                //当前项目的描述(文档描述)
                .description("新微博项目在线API文档")
                //文档版本
                .version("1.0")
                //联系人
                .contact(new Contact("杨宜橦","www.tedu.cn","11399@qq.com"))
                //生成文档信息
                .build();
    }
}
